import QMDialog from "qm-ux/lib/QMDialog";
import Tips from "./tips";
import * as React from "react";

declare let window: any;

let tips = function() {
  QMDialog.load(<Tips />, {
    title: "提示",
    className: "modal-custom"
  });
};

function status() {
  let reactContext = window.getReactContext
    ? window.getReactContext() || {}
    : {};
  const status = reactContext.lifecycle;
  return status;
}

let ExpireLock = () => (target, props, descriptor) => {
  let origin = descriptor.value;

  descriptor.value = new Function(
    "origin",
    "tips",
    "status",
    "return function(){var _this=this;" +
      "if(status() === 'protect' || status() === 'close'){ tips(); return ;} else{ origin.apply(_this,arguments); }}"
  )(origin, tips, status);
};

export default ExpireLock;
